package ac.il.technion.cs236635.project.core.policy;

import java.util.List;

import ac.il.technion.cs236635.project.core.ServerJob;

public class LimittedBufferRedirectPolicy implements AcceptancePolicy {

	private Integer queueSize = 0;

	public LimittedBufferRedirectPolicy( int queueSize) { // TODO: Need to add parameter to handle cluster communication
		this.queueSize = queueSize;
	}
	
	@Override
	// Need to find another server in the cluster
	// to transfer the job in case there is no more place 
	// inside the buffer.
	public boolean accept( ServerJob job, List<ServerJob> queue) {
		if ( queue.size() >= queueSize) {
			if ( job.getRejectListener() != null)
				job.getRejectListener().notifyRejected( job);
			return false;
		}
		queue.add( queue.size( ), job);
		return true;
	}

}
